/*
 * p624.cpp
 *
 *  Created on: 2013-3-14
 *      Author: zy
 */

#include<cstdio>
#include<cstring>
const int maxn=10010;
int f[21][maxn],v[25],path[25][maxn];

int main()
{
	int n,t;
	while(scanf("%d%d",&n,&t)!=EOF)
	{
		for(int i=1;i<=t;i++)
			scanf("%d",&v[i]);
		memset(f,0,sizeof(f));
		memset(path,0,sizeof(path));
		for(int i=1;i<=t;i++)
		{
			for(int j=0;j<=n;j++)
			{
				if(j-v[i]>=0&&f[i-1][j-v[i]]+v[i]>=f[i-1][j])
				{
					f[i][j]=f[i-1][j-v[i]]+v[i];
					path[i][j]=i;
				}
				else
				{
					f[i][j]=f[i-1][j];
					path[i][j]=-1;
				}
			}
		}
		int ans[25],cnt=0,i=t,j=n;
		while(i)
		{
			if(path[i][j]!=-1)
			{
				cnt++;
				ans[cnt]=v[path[i][j]];
				j-=ans[cnt];
			}
			i--;
		}
		for(i=cnt;i>=1;i--)
			printf("%d ",ans[i]);
		printf("sum:%d\n",f[t][n]);
	}
	return 0;
}

